Skip to content

Conversation

@BatuhanSA
Copy link
Contributor

This PR adds a new CLI command for setting configuration options, along with the related tests.
It also improves the CLI testing infrastructure by allowing developers to specify the working directory (cwd) for their CLI tests.

Copy link
Contributor

@eriq-augustine eriq-augustine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pretty good start.

There are some design issues that are making things awkward.
Remember if things are awkward or start to smell,
it could indicate a design issue.

Comment on lines 110 to 111
if (cwd is not None):
self.cwd = self._expand_paths(cwd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually modify init inputs before setting them as members.
So do modification before setting self.cwd.

Copy link
Contributor

@eriq-augustine eriq-augustine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Architecture is looking better.

@@ -0,0 +1,81 @@
"""
Set a configuration option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is incorrect.

def run_cli(args: argparse.Namespace) -> int:
""" Run the CLI. """

config: typing.Dict[str, str] = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name needs more context.
config is a bad name because it does not contain current configuration options.
config_to_set (as you have in the args) is fine.

(key, value) = edq.core.config._parse_cli_config_option(config_option)
config[key] = value

# Defaults to the local configuration if no configuration type is specified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Defaults/Default/

if (args.write_local):
local_config_path = args._config_params[edq.core.config.LOCAL_CONFIG_PATH_KEY]
if (local_config_path is None):
local_config_path = args._config_params[edq.core.config.FILENAME_KEY]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put a newline after this.

edq.core.config.write_config_to_file(global_config_path, config)
elif (args.write_file_path is not None):
edq.core.config.write_config_to_file(args.write_file_path, config)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an else and raise an exception.
We usually do this with things like this and enums to protect us in the future if someone adds a new possible value.
Like if we decided to add system-level config, then an else would protect us.

def _parse_cli_config_option(
config_option: str,
) -> typing.Tuple[str, str]:
""" Parse and validate a CLI configuration option string, returs the resulting config option as a key value pair. """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/returs/returns/

def _parse_cli_config_option(
config_option: str,
) -> typing.Tuple[str, str]:
""" Parse and validate a CLI configuration option string, returs the resulting config option as a key value pair. """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention in this comment what the values you are parsing look like.

return config, sources
return config, sources, config_params

def _parse_cli_config_option(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move away from saying these are "CLI" options,
and instead refer to them as string options.
(Since non-CLI code is allowed to call this.)

Comments and exceptions will need to be updated to reflect this.

return key, value

def _validate_config_key(config_key: str, config_value: str) -> str:
""" Validate a configuration key and return its stripped version. """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/stripped/clean/

You may want to do other cleaning in the future.

Comment on lines +107 to +112
self.work_dir: str = os.getcwd()
""" The directory the test runs from. """

if (work_dir is not None):
work_dir_expanded = self._expand_paths(work_dir)
self.work_dir = work_dir_expanded
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!

A relevant comment was marked resolved, but not handled.
Comment is outdated, but now unresolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants